<?php
class BegHouseAction extends BaseAction
{

    public function index()
    {
        if (!$this->isPost())
        {
            $this->display();
        }
        else
        {
        	/* if(!isset($_SESSION['userinfo']['v_id']) || empty($_SESSION['userinfo']['v_id']))
        	{
        		self::show_msg('请先登录');
        	}  */
        	if(empty($_POST['district']) || !isset($_POST['district']))
        	{
        		self::show_msg('没有选择区域');
        	}
        	if(empty($_POST['title']) || !isset($_POST['title']))
        	{
        		self::show_msg('没有填标题');
        	}
        	if(!isset($_POST['hope_price']) && intval($_POST['hope_price']) < 0 )
        	{
        		self::show_msg('期望价钱不能为空并且必须是大于0的数字');
        	}
        	if(!isset($_POST['hope_area']) && intval($_POST['hope_area']) < 0 )
        	{
        		self::show_msg('面积不能为空并且必须是大于0的数字');
        	}
        	if(empty($_FILES) || !isset($_FILES))
        	{
        		self::show_msg('没有上传图片');
        	}
        	if(empty($_POST['type']) || !isset($_POST['type']))
        	{
        		self::show_msg('没有选择类型');
        	}
            //获得图片
            $newname = ROOT_DIR . DS . 'Public/Upload/';
            $pic = $_FILES['img'];
            import('ORG.NET.UploadFile');
            $U = new UploadFile('', '', '', $newname, 'uniqid');
            $name = $U->uploadOne($pic, $newname);
            $data['district'] = filter_str($_POST['district']);
            $data['picurl'] = $name[0]['savename'];
            $data['valid_time'] = filter_str($_POST['valid_time']);
            $data['title'] = filter_str($_POST['title']);
            $data['istop'] = filter_str($_POST['istop']);
            $data['hope_price'] = filter_str($_POST['hope_price']);
            $data['hope_layout'] = filter_str($_POST['hope_layout']);
            $data['hope_area'] = filter_str($_POST['hope_area']);
            if($_POST['device'] && is_array($_POST['device']))
            {
            	$data['device'] =	implode('||', $_POST['device']);
            }
            $data['hope_fitment'] =	filter_str($_POST['hope_fitment']);
            $data['hope_floor'] = filter_str($_POST['hope_floor']);
            $data['memo'] = filter_str($_POST['memo']);
            $data['status'] = 1;
            $data['type'] = filter_int($_POST['type']);
           	$data['uid'] = $_SESSION['userinfo']['v_id'];
           	$data['uid'] = 11;
           	$data['bus'] = filter_str($_POST['bus']);
           	$result = M("dc_beghouse")->data($data)->add();
            if ($result)
            {
                $this->assign("jumpUrl", "__APP__");
                $this->assign("waitSecond", 3);
                $this->success("发布成功，等待审核！！！");
            }
            else
            {
            	$this->assign("jumpUrl", "__URL__/index");
            	$this->assign("waitSecond", 3);
            	$this->error("发布失败！！！");
            }
        }
    }
    
    static private function show_msg($title)
    {
    	if($title == '请先登录')
    	{
    		echo "
    		<script>
    		alert('请先登录');
    		window.location.href = '/index.php/login';
    		</script>
    		";
    		exit('aa');
    	}
    	echo "
    		<script>
    			alert('".$title."');
    			window.location.href = '/index.php/beghouse';
    		</script>
    	";
    	exit;
    }
}

?>

